$(function(){
	editorInit();
    $('input').iCheck({
		checkboxClass: 'icheckbox_square-green',
		radioClass: 'iradio_square-green',
		increaseArea: '-10' // optional
	});
    var endDate = new Date();
    endDate.setMonth(endDate.getMonth()+2);
    $('.form_datetime').datetimepicker({
    	format:'yyyy-mm',
		language:  'zh-CN',
		weekStart: 1,
		todayBtn:  1,
		autoclose: 1,
		todayHighlight: 1,
		startView: 4,
		minView: 3,
		forceParse: 0,
		endDate:endDate,
    }).on('changeDate', function(ev){
		var newdate = $(this).val();
		var arr = newdate.split('-');
		var smounth = parseInt(arr[1])+2;
		var sDate = arr[0]+"-"+smounth+'-01';
		if($(this).parent().next().find('input').hasClass('form_datetime')){
			$(this).parent().next().find('input').datetimepicker('setStartDate', newdate);
		}
		if($(this).parent().prev().find('input').hasClass('form_datetime')){
			$(this).parent().prev().find('input').datetimepicker('setEndDate', sDate);
		}
	});
    $('.form_datetime2').datetimepicker({
        format:'yyyy',
        language:  'zh-CN',
        weekStart: 1,
        todayBtn:  1,
        autoclose: 1,
        todayHighlight: 1,
        startView: 4,
        minView: 4,
        forceParse: 0,
        endDate:endDate,
    });
	$(document).on('submit','.moreinfo_edit',function(){
		$(":submit",this).attr("disabled","disabled");
		var form =$('#moreinfo_edit');
		var data = form.serializeArray();
		var params = {
				url: '/member/resume/resume-create',
				type: 'POST',
				dataType: 'json',
				data: data,
		};
		var container = $('#resume_info_container');
		var template = _.template($('#userinfo-template').html());
		$.ajax(params).done(function(resp){
			if(resp.status == 'success') {
				$("#userinfo_save").removeAttr("disabled");
				container.html(template({item:resp.data}));
				$('#add_new_experience').find('input[name=resume_id]').val(resp.data.id);
				$('#add_new_educational').find('input[name=resume_id]').val(resp.data.id);
				$('#add_new_projects').find('input[name=resume_id]').val(resp.data.id);
				$('#intro_edit').find('input[name=resume_id]').val(resp.data.id);
				layer.msg('保存简历信息成功，请进一步完善简历');
				$('#resume-other-more-info').removeClass('hide');
			}else{
				$(":submit",this).removeAttr("disabled");
				layer.open({title:'提示',content:resp.msg});
			}
		}).fail(function(erro){
			$("#userinfo_save").removeAttr("disabled");
			error(erro);
		});
		return false;
	});
});
function error(erro){
	var response = eval('(' + erro.responseText + ')');
	var errors = '';
    $.each(response,function(k,v){
        errors +="<div>"+v+"</div>";
    })
    layer.open({
        title: '系统提示',
        content: errors
    });
}